<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>1-3 jQuery和js不同使用方法演示</title>
    <link rel="stylesheet" href="../css/bootstrap-3.3.6.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body>
<div class="container">
    <h1>1-3 jQuery和js不同使用方法演示</h1>
    <br>
    <form>
        <div class="checkbox">
            <div class="form-group">
                <label>
                    <input id="test1" type="checkbox">通过javascript判断
                </label>
                <pre>
                    if ($test1[0].checked) {
                        alert("这个复选框通过javascript判断被选中!");
                    }
                </pre>
            </div>
            <div class="form-group">
                <label>
                    <input id="test2" type="checkbox">通过jQuery判断
                </label>
                <pre>
                    if ($test2.is(":checked")) {
                        alert("这个复选框通过jQuery判断被选中!");
                    }
                </pre>
            </div>
        </div>
    </form>
</div>
<script src="../js/jquery-2.2.4.js"></script>
<script src="../js/main.js"></script>
<script>
    $(function () {
        var $test1 = $("#test1");
        var test1 = $test1[0];
        $test1.click(function () {
            if (test1.checked) {
                alert("这个复选框通过javascript判断被选中!");
            }
        });

        var $test2 = $("#test2");
        var test2 = $test2[0];
        $test2.click(function () {
            if ($test2.is(":checked")) {
                alert("这个复选框通过jQuery判断被选中!");
            }
        })

    })
</script>

</body>
</html>